package com.yulebaby.callsenter.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

/**
 * @author YK
 * @date 2017-1-5.
 */

public class BitmapUtils {
    /**
     * Bitmap缩小的方法
     *
     * @param bitmap
     * @param ratio 缩小比例
     * @return
     */
    public static Bitmap smallBitmap(Bitmap bitmap,float ratio) {
        Matrix matrix = new Matrix();
        matrix.postScale(ratio, ratio); // 长和宽放大缩小的比例

        Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);
        return resizeBmp;
    }

    public static Bitmap decodeBitmap(String filePath) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
        if (bitmap == null) {//bitmap为空

        }
        float realWidth = options.outWidth;
        float realHeight = options.outHeight;
        int scale = (int) ((realHeight > realWidth ? realHeight : realWidth) / 240);
        if (scale <= 0) {
            scale = 1;
        }
        options.inSampleSize = scale;
        options.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(filePath, options);
        return bitmap;
    }

}
